﻿using EPiServer.Core;
using PageTypeBuilder;

namespace EPiMVC.Templates.Web.PageTypes
{
    [PageType(Name = "Standard page", AvailablePageTypes = new[] { typeof(StandardPage) })]
    public class StandardPage : PublicPage
    {
        protected StartPage StartPage;

        public StandardPage(StartPage startPage)
        {
            StartPage = startPage;
        }

        [PageTypeProperty(Type = typeof(PropertyString))]
        public virtual string Heading
        {
            get
            {
                string heading = this.GetPropertyValue(page => page.Heading, false);

                if (!string.IsNullOrEmpty(heading))
                    return heading;

                return PageName;
            }
        }

        [PageTypeProperty]
        public virtual string MainBody { get; set; }

        public override string Title
        {
            get { return string.Format("{0} - {1}", PageName, StartPage.TitleSuffix); }
        }
    }
}